package com.sohu.tv.utils;

import java.io.UnsupportedEncodingException;  

import org.apache.commons.codec.binary.Base64;  
import org.springframework.util.DigestUtils;



public class SecretUtil {
	/** 
     * 编码 
     * param cookieStr 
     * return 
     */  
    public static String encodeBase64(String cookieStr){  
          
        try {  
            cookieStr = new String(Base64.encodeBase64(cookieStr.getBytes("UTF-8")));  
        } catch (UnsupportedEncodingException e) {  
            // TODO Auto-generated catch block  
            e.printStackTrace();  
        }  
        return cookieStr;  
    }  
  
    /** 
     * 解码 
     * param cookieStr 
     * return 
     */  
    public static String decodeBase64(String cookieStr){  
        try {  
            cookieStr = new String(Base64.decodeBase64(cookieStr.getBytes()), "UTF-8");  
        } catch (UnsupportedEncodingException e) {  
            // TODO Auto-generated catch block  
            e.printStackTrace();  
        }  
        return cookieStr;  
    }  
    
    /**
     * 生成MD5签名
     * @param str
     * @param key
     * @return
     */
    public static String getMD5(String str,String key){
			String parameter = str + key;
			String value = DigestUtils.md5DigestAsHex(parameter.getBytes());
			return value;
    }
}
